#include <rtthread.h>
#include "E53_SC2.h"
#include "drv_lcd.h"


int main(void)
{
    E53_SC2_Data data;
    int X = 0, Y = 0, Z = 0;
    E53_SC2_Init();
    while(1)
    {
        E53_SC2_Read_Data(&data);

        rt_kprintf("\r\n******************************Temperature      is  %d\r\n", (int)data.Temperature);
        rt_kprintf("\r\n******************************Accel[ACCEL_X_AXIS] is  %d\r\n", (int)data.Accel[ACCEL_X_AXIS]);
        rt_kprintf("\r\n******************************Accel[ACCEL_Y_AXIS] is  %d\r\n", (int)data.Accel[ACCEL_Y_AXIS]);
        rt_kprintf("\r\n******************************Accel[ACCEL_Z_AXIS] is  %d\r\n", (int)data.Accel[ACCEL_Z_AXIS]);
        
        lcd_show_string(5, 100, 24, "TEMP:%d     ", (int)data.Temperature);

        lcd_show_string(5, 130, 24, "ACCEL_X:%d    ", (int)data.Accel[ACCEL_X_AXIS]);

        lcd_show_string(5, 160, 24, "ACCEL_Y:%d    ", (int)data.Accel[ACCEL_Y_AXIS]);

        lcd_show_string(5, 190, 24, "ACCEL_Z:%d    ", (int)data.Accel[ACCEL_Z_AXIS]);

        if (X == 0 && Y == 0 && Z == 0) {
            X = (int)data.Accel[ACCEL_X_AXIS];
            Y = (int)data.Accel[ACCEL_Y_AXIS];
            Z = (int)data.Accel[ACCEL_Z_AXIS];
        } else {
            if (X + 100 < data.Accel[ACCEL_X_AXIS] || X - 100 > data.Accel[ACCEL_X_AXIS] ||
                Y + 100 < data.Accel[ACCEL_Y_AXIS] || Y - 100 > data.Accel[ACCEL_Y_AXIS] ||
                Z + 100 < data.Accel[ACCEL_Z_AXIS] || Z - 100 > data.Accel[ACCEL_Z_AXIS]) {
                E53_SC2_LedD1_Set(OFF);
                E53_SC2_LedD2_Set(ON);
            } else {
                E53_SC2_LedD1_Set(ON);
                E53_SC2_LedD2_Set(OFF);
            }
        }
        rt_thread_mdelay(2000);
    }
}
